#!/usr/bin/env python
# -*- coding:utf-8 -*-
import requests
# UA：User-Agent （请求载体的身份标识）
# UA伪装：门户网站的服务器会检测对应请求的身份标识，如果检测到请求的载体是某一款浏览器，说明该请求是正常请求
if __name__ == "__main__":
    # UA伪装：将对应的User-Agent 封装到字典
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52'
    }
    url = "https://sogou.com/web"
    # 处理url携带参数：封装到字典中
    kw = input('enter a word:')
    param = {
        'query': kw
    }
    response = requests.get(url, param, headers = headers)
    page_text = response.text
    fileName = kw + '.html'
    with open('data/' + fileName, 'w', encoding='utf-8') as fp:
        fp.write(page_text)